﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class WorkareaResponseContext : BaseResponseContext
	{
		IList<WorkArea> terminologies;
		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (document == null)
				return;

			XmlNode workareanode = document.SelectSingleNode("//WorkAreas");

			ParseExtendedInfo(workareanode);

			XmlNodeList nodes = document.SelectNodes("//WorkAreas/WorkArea");

			terminologies = new List<WorkArea>();

			foreach (XmlNode node in nodes)
			{
				WorkArea terminology = new WorkArea();
				if (node.Attributes["workAreaId"] != null)
					terminology.Id = node.Attributes["workAreaId"].Value;
				if (node.Attributes["workAreaName"] != null)
					terminology.Name = node.Attributes["workAreaName"].Value;
				terminologies.Add(terminology);
			}


			FireChanges();
		}

		public override object GetContext()
		{
			return terminologies;
		}
	}
}